package fact.view.controller;

import java.sql.SQLException;
import java.util.Calendar;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.CustomScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;

import org.icefaces.ace.event.RowEditEvent;

import fact.view.DTO.FactDTO;
import fact.view.model.FactModelBean;


@ManagedBean(name = "factMstBean")
//@RequestScoped
@CustomScoped(value = "#{window}")
public class FactMstBean {
	
	private List<FactDTO> factData;
	 
    @ManagedProperty(value="#{factModelBean}")
    private FactModelBean factModelBean;


	public List<FactDTO> getFactData() {
		return factData;
	}

	public void setFactData(List<FactDTO> factData) {
		this.factData = factData;
	}

	public FactModelBean getFactModelBean() {
		return factModelBean;
	}

	public void setFactModelBean(FactModelBean factModelBean) {
		this.factModelBean = factModelBean;
	}
	
	

	@PostConstruct
	public void init() {	
		 
		try
		{
		
			this.factData=factModelBean.getMstFactList();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void editFact(RowEditEvent event) throws SQLException
	{
		FactDTO factDto = (FactDTO) event.getObject();
//		FactDTO fdto = (FactDTO) event.getObject();
//		fdto.setFactId(factDto.getfa);
//		fdto.setFactName(factName);
//		fdto.setValueFrom(valueFrom);
//		fdto.setValueTo(valueTo);
//		fdto.setAlignment(alignment);
//		fdto.setIsActive(isActive);
//		fdto.setIsMandatory(isMandatory);
//		fdto.setValidationText(validationText);
		
		factModelBean.updateMstFact(factDto);
		
		System.out.println(factDto.getFactName());
		
		System.out.println("Hello Ifti how ar eyou?");
	}
	
	public FactMstBean()
	{

	}
	

}
